package api_day11;
/*
    线程类常用方法测试
 */
public class ThreadAPIDemo {
    public static void main(String[] args) throws InterruptedException {
        ThreadDemo t1 = new ThreadDemo();
        ThreadDemo t2 = new ThreadDemo();
        System.out.println(t1.getName());   //Thread-0
        System.out.println(t2.getName());   //Thread-1
        t1.setName("MyThread");
        System.out.println(t1.getName());   //MyThread
        t1.start();
        int p1 = t1.getPriority();  //获取this线程的优先级，默认为5
        System.out.println(p1); //5
        Thread.sleep(5000); //休眠5秒
        t2.start();
        int p2 = t2.getPriority();  //获取this线程的优先级，默认为5
        System.out.println(p2); //5
        Thread current = Thread.currentThread();
        System.out.println(current.getName());  //main
        int pm = current.getPriority(); //获取this线程的优先级，默认为5
        System.out.println(pm); //5
        Thread.sleep(3000);
        //守护线程设置与执行效果
        RunDemo run = new RunDemo();
        Thread t3 = new Thread(run,"保护");
        Thread t4 = new Thread(run,"保安");
        t4.setDaemon(true);
        t3.start();
        t4.start();
    }
}
